package office.action.business;

import java.util.List;
import java.util.Map;

import office.action.business.form.SupplierConditionForm;
import office.action.business.form.SupplierForm;
import office.action.business.wrapper.SupplierWrapper;
import office.service.business.ISupplierService;
import platform.common.action.BaseAction;
import platform.common.bo.Page;
import platform.util.Util;

/**
 * 
 * 供应商
 * 
 * @author ZhangYQ
 * 
 */
public class SupplierAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private ISupplierService supplierService;
	private Page page; // 分页信息
	private List<SupplierWrapper> wrapperList;
	private SupplierForm form;
	private SupplierConditionForm condition;
	private String id;
	@SuppressWarnings("unchecked")
	private Map map; //供应商类别
	/**
	 * 获取所有的供应商以及根据条件进行查询
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findAllSupplier() throws Exception {
		page = supplierService.getPageInfo(condition);
		wrapperList = supplierService.findAllSupplier(condition,page);
		//获取供应商的类别
		map = Util.parsePropertiesReturnMap("project", "supplierType.size");
		if(condition!=null){
			return "listSupplierByPage";
		}
		return "findAllSupplier";
	}

	/**
	 * 初始化编辑供应商页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEditSupplier() throws Exception {
		if(null!=id&&!"".equals(id)){
			form = supplierService.getById(id);
		}
		//获取供应商的类别
		map = Util.parsePropertiesReturnMap("project", "supplierType.size");
		return "gotoEditSupplier";
	}

	/**
	 * 编辑供应商
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editSupplier() throws Exception {
		try {
			supplierService.editSupplier(form);
			if (null == form.getId()
					|| ("").equals(form.getId())) {
				this.getAjaxMessagesJson().setMessage(true, "", "新建成功");
			} else {
				this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
			}

		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	/**
	 * 
	 * <br/>
	 * 方法描述:分页条件查询产品结构
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listSupplierByPage() throws Exception {
		try {
			wrapperList = supplierService.findAllSupplier(condition, page);
			//获取供应商的类别
			map = Util.parsePropertiesReturnMap("project", "supplierType.size");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return "listSupplierByPage";
	}

	/**
	 * 初始化产品结构列表操作菜单
	 * 
	 * @return
	 * @throws Exception
	 */

	public String gotoSupplierMenu() throws Exception {
		return "gotoSupplierMenu";
	}

	/**
	 * 跳转到供应商删除确认页面
	 */
	public String gotoDeleteSupplier(){
		return "gotoDeleteSupplier";
	}
	
	/**
	 * 删除供应商
	 * @return
	 * @throws Exception
	 */
	public String delSupplier() throws Exception {
		try {
			supplierService.delSupplierById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "操作成功");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return RESULT_AJAXJSON;
	}

	public ISupplierService getSupplierService() {
		return supplierService;
	}

	public void setSupplierService(ISupplierService supplierService) {
		this.supplierService = supplierService;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<SupplierWrapper> getWrapperList() {
		return wrapperList;
	}

	public void setWrapperList(List<SupplierWrapper> wrapperList) {
		this.wrapperList = wrapperList;
	}

	public SupplierForm getForm() {
		return form;
	}

	public void setForm(SupplierForm form) {
		this.form = form;
	}

	public SupplierConditionForm getCondition() {
		return condition;
	}

	public void setCondition(SupplierConditionForm condition) {
		this.condition = condition;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	@SuppressWarnings("unchecked")
	public Map getMap() {
		return map;
	}
	@SuppressWarnings("unchecked")
	public void setMap(Map map) {
		this.map = map;
	}
	
}
